<?php
class Application_Model_CalRisk
{
	protected $_dbTable;
	public $_mStockDateId;
	public $_mStockCode;
	public $_mDate;
	public $_mHsrr;
	public $_mPlRuiRo;
	public $_mPlLoiTuc;
	public $_mPLRuiRoTK;
	public $_mSoNgayTk;
	public $_mComovement;
	public $_mCorelation;
	public $_mCanhBaoPp;
	public $_mGia;
	public $_mThayDoi;
	public $_mQuantile1;
	public $_mQuantile2;
	public $_mRet5d;
	public $_mVol5d;
	public $_mRet1m;
	public $_mVol1m;
	public $_mRet3m;
	public $_mVol3m;
	public $_mRet6m;
	public $_mVol6m;
	public $_mRet12m;
	public $_mVol12m;
	public $_mRet24m;
	public $_mVol24m;
	public $_mVolume5d;
	public $_mVolume1m;
	public $_mVolume3m;
	public $_mVolume6m;
	public $_mVolume12m;
	public $_mKhoiLuongLuuHanh;
	public $_mKhoiLuongNiemYet;
	public $_mVonThiTruong;
	public $_mSharpe12m;

	public function getStockDateId(){
		return $this->_mStockDateId;
	}
	public function setStockDateId($value){
		$this->_mStockDateId = $value;
		return $this;
	}
	public function getStockCode(){
		return $this->_mStockCode;
	}
	public function setStockCode($value){
		$this->_mStockCode = $value;
		return $this;
	}
	public function getDate(){
		return $this->_mDate;
	}
	public function setDate($value){
		$this->_mDate = $value;
		return $this;
	}
	public function getHsrr(){
		return $this->_mHsrr;
	}
	public function setHsrr($value){
		$this->_mHsrr = $value;
		return $this;
	}
	public function getPlRuiRo(){
		return $this->_mPlRuiRo;
	}
	public function setPlRuiRo($value){
		$this->_mPlRuiRo = $value;
		return $this;
	}
	public function getPlLoiTuc(){
		return $this->_mPlLoiTuc;
	}
	public function setPlLoiTuc($value){
		$this->_mPlLoiTuc = $value;
		return $this;
	}
	public function getPLRuiRoTK(){
		return $this->_mPLRuiRoTK;
	}
	public function setPLRuiRoTK($value){
		$this->_mPLRuiRoTK = $value;
		return $this;
	}
	public function getSoNgayTk(){
		return $this->_mSoNgayTk;
	}
	public function setSoNgayTk($value){
		$this->_mSoNgayTk = $value;
		return $this;
	}
	public function getComovement(){
		return $this->_mComovement;
	}
	public function setComovement($value){
		$this->_mComovement = $value;
		return $this;
	}
	public function getCorelation(){
		return $this->_mCorelation;
	}
	public function setCorelation($value){
		$this->_mCorelation = $value;
		return $this;
	}
	public function getCanhBaoPp(){
		return $this->_mCanhBaoPp;
	}
	public function setCanhBaoPp($value){
		$this->_mCanhBaoPp = $value;
		return $this;
	}
	public function getGia(){
		return $this->_mGia;
	}
	public function setGia($value){
		$this->_mGia = $value;
		return $this;
	}
	public function getThayDoi(){
		return $this->_mThayDoi;
	}
	public function setThayDoi($value){
		$this->_mThayDoi = $value;
		return $this;
	}
	public function getQuantile1(){
		return $this->_mQuantile1;
	}
	public function setQuantile1($value){
		$this->_mQuantile1 = $value;
		return $this;
	}
	public function getQuantile2(){
		return $this->_mQuantile2;
	}
	public function setQuantile2($value){
		$this->_mQuantile2 = $value;
		return $this;
	}
	public function getRet5d(){
		return $this->_mRet5d;
	}
	public function setRet5d($value){
		$this->_mRet5d = $value;
		return $this;
	}
	public function getVol5d(){
		return $this->_mVol5d;
	}
	public function setVol5d($value){
		$this->_mVol5d = $value;
		return $this;
	}
	public function getRet1m(){
		return $this->_mRet1m;
	}
	public function setRet1m($value){
		$this->_mRet1m = $value;
		return $this;
	}
	public function getVol1m(){
		return $this->_mVol1m;
	}
	public function setVol1m($value){
		$this->_mVol1m = $value;
		return $this;
	}
	public function getRet3m(){
		return $this->_mRet3m;
	}
	public function setRet3m($value){
		$this->_mRet3m = $value;
		return $this;
	}
	public function getVol3m(){
		return $this->_mVol3m;
	}
	public function setVol3m($value){
		$this->_mVol3m = $value;
		return $this;
	}
	public function getRet6m(){
		return $this->_mRet6m;
	}
	public function setRet6m($value){
		$this->_mRet6m = $value;
		return $this;
	}
	public function getVol6m(){
		return $this->_mVol6m;
	}
	public function setVol6m($value){
		$this->_mVol6m = $value;
		return $this;
	}
	public function getRet12m(){
		return $this->_mRet12m;
	}
	public function setRet12m($value){
		$this->_mRet12m = $value;
		return $this;
	}
	public function getVol12m(){
		return $this->_mVol12m;
	}
	public function setVol12m($value){
		$this->_mVol12m = $value;
		return $this;
	}
	public function getRet24m(){
		return $this->_mRet24m;
	}
	public function setRet24m($value){
		$this->_mRet24m = $value;
		return $this;
	}
	public function getVol24m(){
		return $this->_mVol24m;
	}
	public function setVol24m($value){
		$this->_mVol24m = $value;
		return $this;
	}
	public function getVolume5d(){
		return $this->_mVolume5d;
	}
	public function setVolume5d($value){
		$this->_mVolume5d = $value;
		return $this;
	}
	public function getVolume1m(){
		return $this->_mVolume1m;
	}
	public function setVolume1m($value){
		$this->_mVolume1m = $value;
		return $this;
	}
	public function getVolume3m(){
		return $this->_mVolume3m;
	}
	public function setVolume3m($value){
		$this->_mVolume3m = $value;
		return $this;
	}
	public function getVolume6m(){
		return $this->_mVolume6m;
	}
	public function setVolume6m($value){
		$this->_mVolume6m = $value;
		return $this;
	}
	public function getVolume12m(){
		return $this->_mVolume12m;
	}
	public function setVolume12m($value){
		$this->_mVolume12m = $value;
		return $this;
	}
	public function getKhoiLuongLuuHanh(){
		return $this->_mKhoiLuongLuuHanh;
	}
	public function setKhoiLuongLuuHanh($value){
		$this->_mKhoiLuongLuuHanh = $value;
		return $this;
	}
	public function getKhoiLuongNiemYet(){
		return $this->_mKhoiLuongNiemYet;
	}
	public function setKhoiLuongNiemYet($value){
		$this->_mKhoiLuongNiemYet = $value;
		return $this;
	}
	public function getVonThiTruong(){
		return $this->_mVonThiTruong;
	}
	public function setVonThiTruong($value){
		$this->_mVonThiTruong = $value;
		return $this;
	}
	public function getSharpe12m(){
		return $this->_mSharpe12m;
	}
	public function setSharpe12m($value){
		$this->_mSharpe12m = $value;
		return $this;
	}


	public function setDbTable($dbTable){
		if (is_string($dbTable))
			$dbTable = new $dbTable();
		if (!$dbTable instanceof Zend_Db_Table_Abstract)
			throw new Exception('Invalid table data gateway provided');
		$this->_dbTable = $dbTable;
		return $this;
	}
	public function getDbTable(){
		if (null === $this->_dbTable)
			$this->setDbTable('Application_Model_DbTable_CalRisk');
		return $this->_dbTable;
	}
	public function save(Application_Model_CalRisk $old = null){
		$item = $this;
		$data = array();
		if(isset($item->_mStockDateId)) $data['stock_date_id'] = $item->_mStockDateId;
		if(isset($item->_mStockCode)) $data['stock_code'] = $item->_mStockCode;
		if(isset($item->_mDate)) $data['date'] = $item->_mDate;
		if(isset($item->_mHsrr)) $data['hsrr'] = $item->_mHsrr;
		if(isset($item->_mPlRuiRo)) $data['pl_rui_ro'] = $item->_mPlRuiRo;
		if(isset($item->_mPlLoiTuc)) $data['pl_loi_tuc'] = $item->_mPlLoiTuc;
		if(isset($item->_mPLRuiRoTK)) $data['PLRuiRoTK'] = $item->_mPLRuiRoTK;
		if(isset($item->_mSoNgayTk)) $data['so_ngay_tk'] = $item->_mSoNgayTk;
		if(isset($item->_mComovement)) $data['comovement'] = $item->_mComovement;
		if(isset($item->_mCorelation)) $data['corelation'] = $item->_mCorelation;
		if(isset($item->_mCanhBaoPp)) $data['canh_bao_pp'] = $item->_mCanhBaoPp;
		if(isset($item->_mGia)) $data['gia'] = $item->_mGia;
		if(isset($item->_mThayDoi)) $data['thay_doi'] = $item->_mThayDoi;
		if(isset($item->_mQuantile1)) $data['quantile_1'] = $item->_mQuantile1;
		if(isset($item->_mQuantile2)) $data['quantile_2'] = $item->_mQuantile2;
		if(isset($item->_mRet5d)) $data['ret_5d'] = $item->_mRet5d;
		if(isset($item->_mVol5d)) $data['vol_5d'] = $item->_mVol5d;
		if(isset($item->_mRet1m)) $data['ret_1m'] = $item->_mRet1m;
		if(isset($item->_mVol1m)) $data['vol_1m'] = $item->_mVol1m;
		if(isset($item->_mRet3m)) $data['ret_3m'] = $item->_mRet3m;
		if(isset($item->_mVol3m)) $data['vol_3m'] = $item->_mVol3m;
		if(isset($item->_mRet6m)) $data['ret_6m'] = $item->_mRet6m;
		if(isset($item->_mVol6m)) $data['vol_6m'] = $item->_mVol6m;
		if(isset($item->_mRet12m)) $data['ret_12m'] = $item->_mRet12m;
		if(isset($item->_mVol12m)) $data['vol_12m'] = $item->_mVol12m;
		if(isset($item->_mRet24m)) $data['ret_24m'] = $item->_mRet24m;
		if(isset($item->_mVol24m)) $data['vol_24m'] = $item->_mVol24m;
		if(isset($item->_mVolume5d)) $data['volume_5d'] = $item->_mVolume5d;
		if(isset($item->_mVolume1m)) $data['volume_1m'] = $item->_mVolume1m;
		if(isset($item->_mVolume3m)) $data['volume_3m'] = $item->_mVolume3m;
		if(isset($item->_mVolume6m)) $data['volume_6m'] = $item->_mVolume6m;
		if(isset($item->_mVolume12m)) $data['volume_12m'] = $item->_mVolume12m;
		if(isset($item->_mKhoiLuongLuuHanh)) $data['khoi_luong_luu_hanh'] = $item->_mKhoiLuongLuuHanh;
		if(isset($item->_mKhoiLuongNiemYet)) $data['khoi_luong_niem_yet'] = $item->_mKhoiLuongNiemYet;
		if(isset($item->_mVonThiTruong)) $data['von_thi_truong'] = $item->_mVonThiTruong;
		if(isset($item->_mSharpe12m)) $data['sharpe_12m'] = $item->_mSharpe12m;

		if($old === null)
			$this->getDbTable()->insert($data);
		else{
			$key = array();
			$old->_mStockDateId === null ? $key[] = 'stock_date_id is NULL' : $key['stock_date_id = ?'] =  $old->_mStockDateId;

			$this->getDbTable()->update($data, $key);
		}
	}
	public function delete(){
		$item = $this;
		$old = $item;
		$key = array();
			$old->_mStockDateId === null ? $key[] = 'stock_date_id is NULL' : $key['stock_date_id = ?'] =  $old->_mStockDateId;

		$this->getDbTable()->delete($key);
	}
	public function fetchAll($where = null, $order = null, $count = null, $offset = null){
		$resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset);
		$entries   = array();
		foreach ($resultSet as $row) {
			$item = new Application_Model_CalRisk();
			if(isset($row->stock_date_id))$item->_mStockDateId = $row->stock_date_id;
			if(isset($row->stock_code))$item->_mStockCode = $row->stock_code;
			if(isset($row->date))$item->_mDate = $row->date;
			if(isset($row->hsrr))$item->_mHsrr = $row->hsrr;
			if(isset($row->pl_rui_ro))$item->_mPlRuiRo = $row->pl_rui_ro;
			if(isset($row->pl_loi_tuc))$item->_mPlLoiTuc = $row->pl_loi_tuc;
			if(isset($row->PLRuiRoTK))$item->_mPLRuiRoTK = $row->PLRuiRoTK;
			if(isset($row->so_ngay_tk))$item->_mSoNgayTk = $row->so_ngay_tk;
			if(isset($row->comovement))$item->_mComovement = $row->comovement;
			if(isset($row->corelation))$item->_mCorelation = $row->corelation;
			if(isset($row->canh_bao_pp))$item->_mCanhBaoPp = $row->canh_bao_pp;
			if(isset($row->gia))$item->_mGia = $row->gia;
			if(isset($row->thay_doi))$item->_mThayDoi = $row->thay_doi;
			if(isset($row->quantile_1))$item->_mQuantile1 = $row->quantile_1;
			if(isset($row->quantile_2))$item->_mQuantile2 = $row->quantile_2;
			if(isset($row->ret_5d))$item->_mRet5d = $row->ret_5d;
			if(isset($row->vol_5d))$item->_mVol5d = $row->vol_5d;
			if(isset($row->ret_1m))$item->_mRet1m = $row->ret_1m;
			if(isset($row->vol_1m))$item->_mVol1m = $row->vol_1m;
			if(isset($row->ret_3m))$item->_mRet3m = $row->ret_3m;
			if(isset($row->vol_3m))$item->_mVol3m = $row->vol_3m;
			if(isset($row->ret_6m))$item->_mRet6m = $row->ret_6m;
			if(isset($row->vol_6m))$item->_mVol6m = $row->vol_6m;
			if(isset($row->ret_12m))$item->_mRet12m = $row->ret_12m;
			if(isset($row->vol_12m))$item->_mVol12m = $row->vol_12m;
			if(isset($row->ret_24m))$item->_mRet24m = $row->ret_24m;
			if(isset($row->vol_24m))$item->_mVol24m = $row->vol_24m;
			if(isset($row->volume_5d))$item->_mVolume5d = $row->volume_5d;
			if(isset($row->volume_1m))$item->_mVolume1m = $row->volume_1m;
			if(isset($row->volume_3m))$item->_mVolume3m = $row->volume_3m;
			if(isset($row->volume_6m))$item->_mVolume6m = $row->volume_6m;
			if(isset($row->volume_12m))$item->_mVolume12m = $row->volume_12m;
			if(isset($row->khoi_luong_luu_hanh))$item->_mKhoiLuongLuuHanh = $row->khoi_luong_luu_hanh;
			if(isset($row->khoi_luong_niem_yet))$item->_mKhoiLuongNiemYet = $row->khoi_luong_niem_yet;
			if(isset($row->von_thi_truong))$item->_mVonThiTruong = $row->von_thi_truong;
			if(isset($row->sharpe_12m))$item->_mSharpe12m = $row->sharpe_12m;

			$entries[] = $item;
		}
		return $entries;
	}
    public function getIndex(){
		if(!$this->_mStockDateId)
            return;
        $item = new Application_Model_StockDate();
        $results = $item->fetchAll(array("id=?"=>$this->_mStockDateId));
        if(count($results)==1)
        {
            return $results[0]->getStockExchange();            
        }
	
	}
}
